package com.rivercloud.dao.Impl;

import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.rivercloud.dao.RoleDao;
import com.rivercloud.entity.Role;
import com.rivercloud.entity.UserRole;

public class RoleDaoImpl implements RoleDao{

	 static SqlSessionFactory sqlSessionFactory = null;
	 static{
		 SqlSessionFactoryBuilder sessionFactoryBuilder = new SqlSessionFactoryBuilder();
		 InputStream inputStream =null;
		 
		 try {
			inputStream = Resources.getResourceAsStream("SqlMapConfig.xml");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		sqlSessionFactory = sessionFactoryBuilder.build(inputStream);
	 }
	
	
	

	@Override
	public void addManager(int projectId) {
		SqlSession session = sqlSessionFactory.openSession();
		session.insert("addManager",  projectId);
		session.commit();
		session.close();
		
	}




	@Override
	public void addMember(int projectId) {
		SqlSession session = sqlSessionFactory.openSession();
		session.insert("addMember",  projectId);
		session.commit();
		session.close();
		
	}




	@Override
	public Role findManegerByPid(int projectId) {
		SqlSession session = sqlSessionFactory.openSession();
	
		Role role = session.selectOne("findManegerByPid", projectId);
		session.close();
		return role;
	}
	@Override
	public Role findMemberByPid(int projectId) {
		SqlSession session = sqlSessionFactory.openSession();
		
		Role role = session.selectOne("findMemberByPid", projectId);
		session.close();
		return role;
	}




	

}
